﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tunnel.Tools;

namespace Tunnel.Devices.DeviceEntity.Lamp
{
    public partial class LameForm : Form
    {
        Lamp lamp = new Lamp();
        public LameForm(Lamp lamp)
        {
            InitializeComponent();
            this.lamp = lamp;
            lbLampName.Text = lamp.Name;
            label1.Text = lamp.ParamName;
            try
            {
                if (!Global.PlcStatus[lamp.Protocol])
                {
                    ok.Enabled = false;
                    ok.Text = "故障";
                }
            }
            catch { }

            if (lamp.StatusDescription=="点亮")
            {
                rbOn.Checked = true;
            }
            if(lamp.StatusDescription == "熄灭")
            {
                rbOff.Checked = true;
            }
        }

        private void ok_Click(object sender, EventArgs e)
        {
            if(rbOn.Checked)
            {
                lamp.SendCommand(CommandType.照明开);
                //下面注释的语句可以用于即时假反馈
                //Program.MainForm.ChangeDeviceStatus(lamp.DeviceId, "023", "点亮", lamp.TypeId, DateTime.Now.ToString());
                
            }
            if(rbOff.Checked)
            {
                lamp.SendCommand(CommandType.照明关);
                //下面注释的语句可以用于即时假反馈
                //Program.MainForm.ChangeDeviceStatus(lamp.DeviceId, "024", "熄灭", lamp.TypeId, DateTime.Now.ToString());
            }
            this.Close();
        }

        private void cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
